home *** CD-ROM | disk | FTP | other *** search
/ Gurewich OLE Controls for Visual Basic 4 / Gurewich OLE Controls for Visual Basic 4.iso / ocxprog / programs / ch06 / sprite2.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-24  |  7.5 KB  |  241 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSprite2 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "The Sprite2 Program"
  5.    ClientHeight    =   3930
  6.    ClientLeft      =   1320
  7.    ClientTop       =   1725
  8.    ClientWidth     =   4755
  9.    Height          =   4620
  10.    Icon            =   "SPRITE2.frx":0000
  11.    Left            =   1260
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   262
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   317
  17.    Top             =   1095
  18.    Width           =   4875
  19.    Begin VB.Timer Timer1 
  20.       Interval        =   50
  21.       Left            =   3480
  22.       Top             =   2400
  23.    End
  24.    Begin TegommLibCtl.Tegomm Tegomm1 
  25.       Height          =   495
  26.       Left            =   600
  27.       TabIndex        =   0
  28.       Top             =   120
  29.       Width           =   3510
  30.       _version        =   65536
  31.       _extentx        =   6191
  32.       _extenty        =   873
  33.       _stockprops     =   64
  34.    End
  35.    Begin TegsprLibCtl.TegoSprite sprBus 
  36.       Left            =   960
  37.       Top             =   2040
  38.       _version        =   65536
  39.       _extentx        =   4260
  40.       _extenty        =   2990
  41.       _stockprops     =   0
  42.       spritefilename  =   "c:\ocxprog\programs\ch06\bus0.bmp"
  43.       maskfilename    =   "c:\ocxprog\programs\ch06\Mbus0.bmp"
  44.       spriteleft      =   64
  45.       spritetop       =   136
  46.       spriteheight    =   113
  47.       spritewidth     =   161
  48.    End
  49.    Begin TegsprLibCtl.TegoSprite sprBack 
  50.       Left            =   0
  51.       Top             =   0
  52.       _version        =   65536
  53.       _extentx        =   11165
  54.       _extenty        =   6985
  55.       _stockprops     =   0
  56.       spritefilename  =   "c:\ocxprog\programs\ch06\road.bmp"
  57.       maskfilename    =   "c:\ocxprog\programs\ch06\Mroad.bmp"
  58.       spriteheight    =   264
  59.       spritewidth     =   422
  60.       transparent     =   0   'False
  61.       autosize        =   -1  'True
  62.    End
  63.    Begin VB.Menu mnuFile 
  64.       Caption         =   "&File"
  65.       Begin VB.Menu mnuExit 
  66.          Caption         =   "E&xit"
  67.       End
  68.    End
  69.    Begin VB.Menu mnuEffects 
  70.       Caption         =   "&Effects"
  71.       Begin VB.Menu mnuSound 
  72.          Caption         =   "&Sound"
  73.       End
  74.       Begin VB.Menu mnuBumpyRide 
  75.          Caption         =   "&Bumpy Ride"
  76.       End
  77.    End
  78.    Begin VB.Menu mnuHelp 
  79.       Caption         =   "&Help"
  80.       Begin VB.Menu mnuAbout 
  81.          Caption         =   "&About..."
  82.       End
  83.    End
  84. Attribute VB_Name = "frmSprite2"
  85. Attribute VB_Creatable = False
  86. Attribute VB_Exposed = False
  87. ' All variables must be declared.
  88. Option Explicit
  89. ' Declare handles for the show's sprites.
  90. Dim gBack As Long
  91. Dim gBus0 As Long
  92. Dim gBus1 As Long
  93. Dim gBus2 As Long
  94. Dim gBus3 As Long
  95. Private Sub Form_Load()
  96.    Dim Path
  97.    ' Get the name of the directory where the
  98.    ' program resides.
  99.    Path = App.Path
  100.    If Right(Path, 1) <> "\" Then
  101.       Path = Path + "\"
  102.    End If
  103.   ' Open a WAV file for background music.
  104.   Tegomm1.Visible = False
  105.   Tegomm1.DeviceType = "WaveAudio"
  106.   Tegomm1.filename = Path + "BUS.WAV"
  107.   Tegomm1.Command = "Open"
  108.   ' Initialize all the sprite controls.
  109.   sprBack.InitializeSprite Me.hWnd
  110.   sprBus.InitializeSprite Me.hWnd
  111.       
  112.   ' Open all the sprites that will be used in our show.
  113.   gBack = sprBack.OpenSprite(Path + "ROAD.BMP")
  114.   gBus0 = sprBack.OpenSprite(Path + "BUS0.BMP")
  115.   gBus1 = sprBack.OpenSprite(Path + "BUS1.BMP")
  116.   gBus2 = sprBack.OpenSprite(Path + "BUS2.BMP")
  117.   gBus3 = sprBack.OpenSprite(Path + "BUS3.BMP")
  118. End Sub
  119. Private Sub Form_Paint()
  120.    ' Draw the sprBack sprite inside WinG
  121.    sprBack.SpriteHandle = gBack
  122.    sprBack.DrawSprite
  123.    ' Draw the sprBus sprite inside WinG.
  124.    sprBus.SpriteHandle = gBus0
  125.    sprBus.DrawSprite
  126.    ' Slam WinG into the screen
  127.    sprBack.SlamIt
  128. End Sub
  129. Private Sub Form_Unload(Cancel As Integer)
  130.    ' Close all the sprites of the show.
  131.    sprBack.CloseSprite (gBack)
  132.    sprBack.CloseSprite (gBus0)
  133.    sprBack.CloseSprite (gBus1)
  134.    sprBack.CloseSprite (gBus2)
  135.    sprBack.CloseSprite (gBus3)
  136. End Sub
  137. Private Sub mnuAbout_Click()
  138.    Dim Title
  139.    Dim Msg
  140.    Dim CR
  141.    CR = Chr(13) + Chr(10)
  142.    ' Prepare the title of the About message box.
  143.    Title = "About the Sprite2 Program"
  144.    Msg = "This program was written with Visual "
  145.    Msg = Msg + "Basic for Windows, using the "
  146.    Msg = Msg + "TegoSoft Sprite OCX control. "
  147.    Msg = Msg + CR + CR
  148.    Msg = Msg + "The TegoSoft Sprite OCX control "
  149.    Msg = Msg + "is part of the TegoSoft OCX Control "
  150.    Msg = Msg + "Kit - a collection of various OCX controls. "
  151.    Msg = Msg + CR + CR
  152.    Msg = Msg + "For more information about the "
  153.    Msg = Msg + "TegoSoft OCX Control Kit, contact TegoSoft "
  154.    Msg = Msg + "at:"
  155.    Msg = Msg + CR + CR
  156.    Msg = Msg + "TegoSoft Inc." + CR
  157.    Msg = Msg + "P.O. Box 389" + CR
  158.    Msg = Msg + "Bellmore, NY 11710"
  159.    Msg = Msg + CR + CR
  160.    Msg = Msg + "Phone: (516)783-4824"
  161.    ' Display the About message box.
  162.    MsgBox Msg, vbInformation, Title
  163.    ' If the Sound menu item is checked,
  164.    ' make sure that there is playback after
  165.    ' the user closes the modal message box.
  166.    If mnuSound.Checked Then
  167.       Tegomm1.Command = "Play"
  168.    End If
  169. End Sub
  170. Private Sub mnuBumpyRide_Click()
  171.     ' Toggle the check mark of the Bumpy Ride menu item.
  172.     mnuBumpyRide.Checked = Not mnuBumpyRide.Checked
  173. End Sub
  174. Private Sub mnuExit_Click()
  175.    ' Terminate the program.
  176.    Unload Me
  177. End Sub
  178. Private Sub mnuSound_Click()
  179.   ' Toggle the check mark of the Sound menu item.
  180.   mnuSound.Checked = Not mnuSound.Checked
  181.   ' If the Sound menu item is checked, play the
  182.   ' WAV file. Otherwise, stop playing the WAV file.
  183.   If mnuSound.Checked Then
  184.      Tegomm1.Command = "Play"
  185.   Else
  186.      Tegomm1.Command = "Stop"
  187.   End If
  188. End Sub
  189. Private Sub Tegomm1_Done()
  190.    ' If the Sound menu item is not checked,
  191.    ' terminate this procedure.
  192.    If Not mnuSound.Checked Then
  193.       Exit Sub
  194.    End If
  195.    ' If playback reached the end of the WAV file,
  196.    ' rewind the WAV file and play again.
  197.    If Tegomm1.Position = Tegomm1.Length Then
  198.       Tegomm1.Command = "Prev"
  199.       Tegomm1.Command = "Play"
  200.    End If
  201. End Sub
  202. Private Sub Timer1_Timer()
  203.    Static Bus
  204.    Static BumpPosition
  205.    ' If the program's window is currently minimized,
  206.    ' exit this procedure.
  207.    If Me.WindowState = 1 Then
  208.       Exit Sub
  209.    End If
  210.    ' If the Bumpy Ride menu item is checked,
  211.    ' create the illusion of a bumpy ride.
  212.    If mnuBumpyRide.Checked Then
  213.       If BumpPosition = 0 Then
  214.          sprBus.SpriteTop = sprBus.SpriteTop - 5
  215.          BumpPosition = 1
  216.       Else
  217.          sprBus.SpriteTop = sprBus.SpriteTop + 5
  218.          BumpPosition = 0
  219.       End If
  220.    End If
  221.    ' Draw the background sprite inside WinG.
  222.    sprBack.SpriteHandle = gBack
  223.    sprBack.DrawSprite
  224.    ' Draw the sprBus sprite inside WinG.
  225.    If Bus = 0 Then sprBus.SpriteHandle = gBus0
  226.    If Bus = 1 Then sprBus.SpriteHandle = gBus1
  227.    If Bus = 2 Then sprBus.SpriteHandle = gBus2
  228.    If Bus = 3 Then sprBus.SpriteHandle = gBus3
  229.    sprBus.DrawSprite
  230.    ' Slam WinG into the screen.
  231.    sprBack.SlamIt
  232.    ' Increment the Bus static variable.
  233.    Bus = Bus + 1
  234.    If Bus = 4 Then Bus = 0
  235.    ' Shift the background sprite to the left.
  236.    sprBack.SpriteLeft = sprBack.SpriteLeft - 20
  237.    If sprBack.SpriteLeft <= -100 Then
  238.       sprBack.SpriteLeft = 0
  239.    End If
  240. End Sub
  241.